import SceneNavigator from "../../eazax-ccc/core/SceneNavigator";
import BrowserUtil from "../../eazax-ccc/utils/BrowserUtil";
import CaseManager from "../common/CaseManager";
import Toast from "../common/components/Toast";
import { SceneName } from "../common/constants/Constants";

const {ccclass, property, executionOrder} = cc._decorator;

@ccclass
@executionOrder(-100)
export default class Home extends cc.Component {

    onLoad () {
        this.init()
    }

    start () {
        this.detectCaseParam()
    }

    init () {
        // 设置首页
        SceneNavigator.setHome(SceneName.Home);
    }

    /**
     * 检测 URL 参数跳转示例
     */
    protected detectCaseParam() {
        // 获取链接中的示例参数
        const caseName = BrowserUtil.getUrlParam('case');
        if (caseName) {
            if (CaseManager.hasCase(caseName)) {
                // 跳转到指定示例
                CaseManager.goCase(caseName);
            } else {
                Toast.show('啊这，，，，，没找到这个示例', caseName);
            }
        }
    }
}
